﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;

namespace Database
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="EnumType">The type of the num type.</typeparam>
    /// <typeparam name="BasicType">The type of the asic type.</typeparam>
    
    public class EnumTypeWrapper<EnumType, BasicType>
        where EnumType : struct, IConvertible
        where BasicType : struct, IConvertible
    {

        #region Public Properties

        /// <summary>
        /// Gets or sets the actual enum value.
        /// </summary>
        /// <value>
        /// The value.
        /// </value>
        public EnumType EnumValue
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the basic value.
        /// </summary>
        /// <value>
        /// The basic value.
        /// </value>
        public BasicType BasicValue
        {
            get
            {
                return (BasicType) (EnumValue as IConvertible);
            }
            set
            {
                EnumValue = (EnumType) (value as IConvertible);
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Performs an implicit conversion from <see cref="EnumType"/> to <see cref="Database.EnumTypeWrapper&lt;EnumType,BasicType&gt;"/>.
        /// </summary>
        /// <param name="enumValue">The enum value.</param>
        /// <returns>
        /// The result of the conversion.
        /// </returns>
        public static implicit operator EnumTypeWrapper<EnumType, BasicType>(EnumType enumValue)
        {
            return new EnumTypeWrapper<EnumType, BasicType>() { EnumValue = enumValue };
        }

        /// <summary>
        /// Performs an implicit conversion from <see cref="Database.EnumTypeWrapper&lt;EnumType,BasicType&gt;"/> to <see cref="EnumType"/>.
        /// </summary>
        /// <param name="enumTypeWrapper">The enum type wrapper.</param>
        /// <returns>
        /// The result of the conversion.
        /// </returns>
        public static implicit operator EnumType(EnumTypeWrapper<EnumType, BasicType> enumTypeWrapper)
        {
            return enumTypeWrapper.EnumValue;
        }

        #endregion
    }
}
